#include "ringbuffer_global.h"
#include "ringbuffer.h"

static bool _ispoweroftwo(unsigned int len)
{
    if (((len & len - 1) == 0) && (len != 0))
    {
        return true;
    }
    return false;
}

static unsigned int _uperboundpower2(unsigned int len)
{
    if (len == 0)
    {
        return 1;
    }
    if (len >= (1 << 31))
    {
        return 1 << 31;
    }
    unsigned int temp = len;
    while (!_ispoweroftwo(temp))
    {
        temp = temp & (temp - 1);
    }
     return temp << 1;
}

RingBuffer::~RingBuffer()
{

}

RingBuffer * RingBufferCreator::Generate(unsigned int len)
{
    const unsigned int reslen = _uperboundpower2(len);
    return new RingbufferNormal(reslen);
}

void RingBufferCreator::Destroy(RingBuffer* pInstance)
{
    delete pInstance;
}
